
import random

cnt = 200
i = 0



alls = {}
keys = []
for a in range(1,cnt) :
    print(a)
    for b in range(1, cnt) :
        for c in range(1, cnt) :
            for operator1 in range(1, 5) :
                for operator2 in range(1, 5) :
                    # ## result = random.randint(100,9999)
                    # ## 第一个操作符 1+ 2- 3* 4/
                    # operator1 = random.randint(1,4)
                    # ## 第二个操作符  1+ 2- 3* 4/
                    # operator2 = random.randint(1,4)

                    ## 如果一个是乘除一个是加减， 确保把乘除放在前面
                    if operator2 > 2 and operator1 < 3 :
                        # t = operator2
                        # operator2 = operator1
                        # operator1 = t
                        ## 待处理：怎么把加减放在后面显示                        
                        s = ""
                        rs = 0

                        s += str(b)
                        
                        if operator2 == 1 :
                            s += " + " 
                            rs = b + c
                        elif operator2 == 2 :
                            s += " - "
                            rs = b - c
                        elif operator2 == 3 :
                            s += " × "
                            rs = b * c
                        elif operator2 == 4 :
                            if c == 0 :
                                continue
                            s += " ÷ " 
                            rs = b / c
                        s += str(c) + " = "
                        ## s = str(c) + s + " = "



                        ## s = str(a)
                        if operator1 == 1 :
                            s = " + " + s
                            rs = a + rs
                        elif operator1 == 2 :
                            s = " - " + s
                            rs = a - rs
                        elif operator1 == 3 :
                            s = " × " + s
                            rs = a * rs
                        elif operator1 == 4 :
                            if rs == 0 :
                                continue
                            s = " ÷ " + s
                            rs = a / rs
                        s = str(a) + s

                        if rs == int(rs) and rs >= 0 and rs < 10000:
                            ## 结果是INT 保存起来
                            keys.append(s + str(rs))

                    else :
                        ## 按顺序来
                        s = ""
                        rs = 0
                        s = str(a)
                        if operator1 == 1 :
                            s += " + "
                            rs = a + b
                        elif operator1 == 2 :
                            s += " - "
                            rs = a - b
                        elif operator1 == 3 :
                            s += " × "
                            rs = a * b
                        elif operator1 == 4 :
                            s += " ÷ "
                            rs = a / b

                        s += str(b)
                        
                        if operator2 == 1 :
                            s += " + "
                            rs = rs + c
                        elif operator2 == 2 :
                            s += " - "
                            rs = rs - c
                        elif operator2 == 3 :
                            s += " × "
                            rs = rs * c
                        elif operator2 == 4 :
                            s += " ÷ "
                            rs = rs / c
                        s += str(c) + " = "
                        ## if isinstance(rs, int) and rs >= 0 and rs < 10000:
                        if rs == int(rs) and rs >= 0 and rs < 10000:
                            ## 结果是INT 保存起来
                            keys.append(s + str(rs))
                    ##print(a, "O1:", operator1, b, "O2:", operator2, c, s, rs)

            

# lines = []
# for key in alls:
#     ## print(key, alls[key])
#     line = str(alls[key]) + str(key)
#     lines.append(line)

# f = open("H:\\DEV\\wpython\\math.txt", mode="w")
# f.writelines(lines)
# f.close()

cnt = 1000
i = 0
oks = []
while i < cnt :
    line = random.choice(keys)
    oks.append(line)
    oks.append("\n")
    i += 1

f = open("H:\\DEV\\wpython\\mathoks.txt", mode="w")
f.writelines(oks)
f.close()
